//
//  YZUser.m
//  VET
//
//  Created by Lam BG on 2018/7/2.
//  Copyright © 2018年 YZ. All rights reserved.
//

#import "YZUser.h"

#import "Constant.h"

#import "MJExtension.h"

NSString * const kUserKey = @"kLocalUser";
@implementation YZUser

SingletonM

MJCodingImplementation

- (void)storeUserToLocal:(NSDictionary*)data {
    
    [YZUser mj_objectWithKeyValues:data];
    // 保存到本地
    UserDefaultsAsyncSavaObjToLocal(kUserKey, self);
}

- (YZUser *)getLocalUser {
    
    UserDefaultsGetObjFromLocal(kUserKey);
    
    return self;
}

+ (BOOL)clearLocalUser {
    
    [YZUser memoryDealloc];
    UserDefaultsAsyncSavaObjToLocal(kUserKey, [YZUser sharedInstance]);
    
    return [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (void)memoryDealloc {
    
    // 清除关键的数据
    YZUser *user = [YZUser sharedInstance];
    user.uid = nil;
    user.token = nil;
    user.uniqueId = nil;
    user.avatar = nil;
    user.avatarOriginal = nil;
    user.name = nil;
    user.nickName = nil;
    user.company = nil;
    user.authStatus = 0;
    user.professionType = nil;
    user.province = nil;
    user.city = nil;
    user.phone = nil;
    user.deviceToken = nil;
    user.userProperties = nil;
}

- (NSString *)nickName {
    
    return _nickName?:self.name;
}



// 不会被序列化到本地的数据
//+ (NSArray *)mj_ignoredCodingPropertyNames {
//
//    return @{
//
//             };
//}

+ (NSDictionary*)mj_replacedKeyFromPropertyName {
    
    return @{
             @"uid" : @"id",
             @"nickName" : @"nickname"
             };
}

- (void)dealloc {
    NSLog(@"%@:----释放了",NSStringFromSelector(_cmd));
}

@end
